package com.my.chapter12;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Logger;

public class practice6 {
    public static void main(String[] args) {
        try {
            throw new LoggingException1();
        }catch (Exception e){
            System.err.println("Caught" + e);
        }

        try {
            throw new NullPointerException();
        }catch (NullPointerException e){
            LoggingException2.logException(e);
        }
    }
}

class LoggingException1 extends Exception{
    private static Logger logger = Logger.getLogger("LoggingException1");
    public LoggingException1(){
        StringWriter sw = new StringWriter();
        printStackTrace(new PrintWriter(sw));
        logger.severe(sw.toString());
    }
}

class LoggingException2 extends Exception{
    private static Logger logger = Logger.getLogger("LoggingException2");
    static void logException(Exception e){
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        logger.severe(sw.toString());
    }
}

